package com.panopset.gui.container;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.LayoutManager;

import javax.swing.JRadioButton;

import com.panopset.gui.LookAndFeel;
import com.panopset.swing.FieldGui;
import com.panopset.swing.FontManager;

/**
 * Panopset radio button.
 *
 * @author Karl Dinwiddie
 *
 */
public final class PanRadioButton extends PanField<JRadioButton> {

    /**
     * @param title
     *            If null, there will be no Titled Border.
     * @param label
     *            Label.
     * @param toolTipText
     *            Tool tip text.
     */
    public PanRadioButton(final String title, final String label,
            final String toolTipText) {
        super(title, toolTipText, Boolean.FALSE.toString(),
                new GridLayout(1, 1));
        ((JRadioButton) getInnerComponent()).setText(label);
    }

    /**
     * @param title
     *            If null, there will be no Titled Border.
     * @param toolTipText
     *            Tool tip text.
     */
    public PanRadioButton(final String title, final String toolTipText) {
        super(title, toolTipText, Boolean.FALSE.toString(),
                new GridLayout(1, 1));
    }

    /**
     * @param title
     *            If null, there will be no Titled Border.
     */
    public PanRadioButton(final String title) {
        this(title, "");
        setFieldGui(new PanRadioButtonFieldGui());
    }

    @Override
    public JRadioButton createComponent() {
        JRadioButton rtn = new JRadioButton();
        rtn.setBackground(LookAndFeel.Colors.BG_COLOR.getColor());
        FontManager.register(rtn, FontManager.FontType.plainArial);
        return rtn;
    }

    class PanRadioButtonFieldGui extends FieldGui {

        @Override
        public String getValue() {
            return Boolean.valueOf(getInnerComponent().isSelected()).toString();
        }

        @Override
        public void setValue(final String value) {
            getInnerComponent().setSelected(Boolean.parseBoolean(value));
        }
    }

    @Override
    protected LayoutManager createLayout() {
        return new FlowLayout();
    }

    @Override
    protected boolean isValid(final String valueToCheck) {
        // TODO Auto-generated method stub
        return true;
    }
}
